package com.api.gbhg.lbj.dao;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

import java.util.Map;

/**
 * @author lbj
 * @version 1.0
 * @description: TODO
 * @date 2020/12/31 12:06
 */
public class GeneralProjectDao {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");

    //通用项目 主表数据
    public RecordSetTrans getGeneralProjectMainTable(String requestId) {
        RecordSetTrans rts = new RecordSetTrans();
        String sql = "select t.fzr,t.lcjlsqjlid,t1.id,t.xmmin,t.sbdw,t.sbks,t.jbr,t1.qzhgzyzbsbxq,t1.hwgz,t1.xsfy,t1.fwjqt,t1.zyzcnrwy,t1.je,t1.zhwgz,t1.xecg,t1.gc,t1.fw,t1.fwjqtxgfj,t1.hwgzxgfj,t1.xsgcxgfj from uf_jingfei_version t " +
                "RIGHT JOIN uf_tyxmxzbbb t1 on t.lcjlsqjlid =t1.requestId where t1.requestId IN(" + requestId + ")";
        try {
            logger.info("通用项目主表sql:--->" + sql);
            rts.executeQuery(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }

    //获取数据条数
    public int getGeneralProjectCount(String status, String requestId) {
        RecordSet rs = new RecordSet();
        String StrSQL = "select COUNT(1)AS num from uf_jingfei_version v INNER JOIN uf_tyxmxzbbb t on v.lcjlsqjlid =t.requestId where 1=1";
        if (status.equals("3")) {
            StrSQL = StrSQL + (" AND v.lcztz= 3 AND t.requestId IN(" + requestId + ")");
        } else {
            StrSQL = StrSQL + (" AND v.lcztz<> 3 AND t.requestId IN(" + requestId + ")");
        }
        logger.info("通用项目总条数sql:--->" + StrSQL);
        rs.executeQuery(StrSQL);
        rs.next();
        return rs.getInt("num");
    }

    //经费额度信息查询
    public RecordSet getFundstorageById(String requestid, String table, String schedule) {
        RecordSet rs = new RecordSet();
        String StrSQL = "select v.jbr,v.sbdw,v.xmmin,v.lcbj,v.lcjlsqjlid,v.sydw,d.bmyszcjjfl,d.dyzfjjfl,v.ysnd,v.yszje,d.hjwy from uf_jingfei_version v," + table + " t," + schedule + " d " +
                "where v.lcjlsqjlid=t.requestId and t.id=d.mainid and  v.lcjlsqjlid=" + requestid;
        logger.info("===================table:" + table + ",sql:" + StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }

    //通用项目经费额度信息查询
    public RecordSet getGeneralFundstorageById(String requestid, String table, String schedule) {
        RecordSet rs = new RecordSet();
        String StrSQL = "select v.jbr,v.sbdw,v.xmmin,v.lcbj,v.lcjlsqjlid,v.gkdw,v.sydw,d.bmyszcjjfl,d.dyzfjjfl,v.ysnd,v.yszje,d.hjwy from uf_jingfei_version v," + table + " t," + schedule + " d " +
                "where v.lcjlsqjlid=t.requestId and t.id=d.mainid and  v.lcjlsqjlid=" + requestid;
        logger.info("===================table:" + table + ",sql:" + StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }

    public RecordSet getimportFundstorageById(String requestid, String table, String schedule) {
        RecordSet rs = new RecordSet();
        String StrSQL = "select v.jbr,v.sbdw,v.xmmin,v.lcbj,v.lcjlsqjlid,v.gkdw,v.sydw,d.sheet4_detail2_field2,d.sheet4_detail2_field7,d.sheet4_detail2_field1,d.sheet4_detail2_field3,v.ysnd,v.yszje from uf_jingfei_version v," + table + " t," + schedule + " d " +
                "where v.lcjlsqjlid=t.requestId and t.id=d.mainid and  v.lcjlsqjlid=" + requestid;
        logger.info("========项目导入经费同步sql===========table:" + table + ",sql:" + StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }
    public static RecordSet deleteWorkflowByid(String requestid){
        RecordSet rs=new RecordSet();
        try {
            rs.executeUpdate("delete from uf_jingfei where lcjlid =" + requestid);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return rs;
    }
}
